
package com.ruoyi.gisconverter.ext;


import com.ruoyi.gisconverter.core.type.*;

import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 *
 * @author Emre Demir
 */
public class ExtensionsUtil {

    private final List<FileExtension> extensionList = Arrays.asList(
            new FileExtension("ESRI Shape File (.shp)", "shp", new ShapeFile()),
            new FileExtension("GeoJson (.geojson)", "geojson", new GeoJsonFile()),
            new FileExtension("CSV", "csv", new CsvFile()),
            new FileExtension("KML", "kml", new KmlFile()),
            new FileExtension("GML", "gml", new GmlFile())
    );

    public List<String> getExtensionsFileChooser() {
        return extensionList.stream().map(s -> ("*." + s.getExtension()))
                .collect(Collectors.toList());
    }

    public List<FileExtension> getExtensions(String filter) {
        return extensionList.stream()
                .map(s -> s)
                .filter(s -> !s.getExtension().equals(filter))
                .collect(Collectors.toList());
    }

    public FileExtension getFileExtension(String ext) {
        return extensionList.stream()
                .map(s -> s)
                .filter(s -> s.getExtension().equals(ext))
                .findFirst()
                .get();
    }

}
